package com.nbstar.film.spider.spider;

import com.nbstar.film.spider.domain.FilmSpiderDomain;
import com.nbstar.film.spider.http.FirefoxDriverRequest;

public class SpiderFactory {
    //private static FirefoxDriverRequest firefoxDriverRequest = null;


    public static FirefoxDriverRequest  getWebdriver() {
        FirefoxDriverRequest firefoxDriverRequest = new FirefoxDriverRequest();
        firefoxDriverRequest.setProxy(firefoxDriverRequest.getDefaultProxy());
        firefoxDriverRequest.init(true);

        return firefoxDriverRequest;
    }

    public static FilmSpider create(String spiderType) {

        if (spiderType.equals(FilmSpiderDomain.SPIDER_FROM_IMDB)) {
            return new ImdbSpider();
        }

        if (spiderType.equals(FilmSpiderDomain.SPIDER_FROM_DOUBAN)) {
            DoubanFilmSpider spider = new DoubanFilmSpider();
            spider.setFirefoxDriverRequest(getWebdriver());
            return spider;
        }

        if (spiderType.equals(FilmSpiderDomain.SPIDER_FROM_MAOYAN)) {
            MaoYanSpider spider = new MaoYanSpider();
            spider.setFirefoxDriverRequest(getWebdriver());
            return spider;
        }

        if (spiderType.equals(FilmSpiderDomain.SPIDER_FROM_BAIKE)) {
            return new BaiKeSpider();
        }

        if (spiderType.equals(FilmSpiderDomain.SPIDER_FROM_TVMAO_TV)) {
            TVCatSpider spider = new TVCatSpider(TVCatSpider.MediaType.TV );
            //spider.setFirefoxDriverRequest(getWebdriver());
            return spider;
        }

        if (spiderType.equals(FilmSpiderDomain.SPIDER_FROM_TVMAO_FILM)) {
            TVCatSpider spider = new TVCatSpider(TVCatSpider.MediaType.FILM );
            spider.setFirefoxDriverRequest(getWebdriver());
            return spider;
        }

        if (spiderType.equals(FilmSpiderDomain.SPIDER_FROM_IQY)) {
            IqiyiSpider spider = new IqiyiSpider();
            spider.setFirefoxDriverRequest(getWebdriver());
            return spider;
        }

        if (spiderType.equals(FilmSpiderDomain.SPIDER_FROM_YOUKU)) {
            YouKuSpider spider = new YouKuSpider();
            spider.setFirefoxDriverRequest(getWebdriver());
            return spider;
        }

            if (spiderType.equals(FilmSpiderDomain.SPIDER_FROM_QQ)) {
            VqqSpider spider = new VqqSpider();
            spider.setFirefoxDriverRequest(getWebdriver());
            return spider;
        }

        return null;
    }
}
